<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionView::Helpers::TranslationHelper</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActionView::Helpers::TranslationHelper 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_view/helpers/translation_helper_rb.html">actionpack/lib/action_view/helpers/translation_helper.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>L</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TranslationHelper.html#method-i-l">l</a>,
              </li>
            
              
              <li>
                <a href="TranslationHelper.html#method-i-localize">localize</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>T</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TranslationHelper.html#method-i-t">t</a>,
              </li>
            
              
              <li>
                <a href="TranslationHelper.html#method-i-translate">translate</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-l">
            
              <b>l</b>(*args)
            
            <a href="TranslationHelper.html#method-i-l" name="method-i-l" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-localize">
            
              <b>localize</b>(*args)
            
            <a href="TranslationHelper.html#method-i-localize" name="method-i-localize" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Delegates to <code>I18n.localize</code> with no additional functionality.</p>

<p>See <a
href="http://rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/Base:localize">rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/Base:localize</a>
for more information.</p>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="TranslationHelper.html#method-i-l">l</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-localize_source')" id="l_method-i-localize_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be4a4cd38ff2c2db0f6b69bb72fb3557bd5a6e21/actionpack/lib/action_view/helpers/translation_helper.rb#L69" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-localize_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/translation_helper.rb, line 69</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">localize</span>(*<span class="ruby-identifier">args</span>)
  <span class="ruby-constant">I18n</span>.<span class="ruby-identifier">localize</span>(*<span class="ruby-identifier">args</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-t">
            
              <b>t</b>(key, options = {})
            
            <a href="TranslationHelper.html#method-i-t" name="method-i-t" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-translate">
            
              <b>translate</b>(key, options = {})
            
            <a href="TranslationHelper.html#method-i-translate" name="method-i-translate" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Delegates to <code>I18n#translate</code> but also performs three additional
functions.</p>

<p>First, it’ll pass the <code>rescue_format: :html</code> option to <a
href="../../I18n.html">I18n</a> so that any thrown
<code>MissingTranslation</code> messages will be turned into inline spans
that</p>

<pre class="ruby">* <span class="ruby-identifier">have</span> <span class="ruby-identifier">a</span> <span class="ruby-string">&quot;translation-missing&quot;</span> <span class="ruby-keyword">class</span> <span class="ruby-identifier">set</span>,
* <span class="ruby-identifier">contain</span> <span class="ruby-identifier">the</span> <span class="ruby-identifier">missing</span> <span class="ruby-identifier">key</span> <span class="ruby-identifier">as</span> <span class="ruby-identifier">a</span> <span class="ruby-identifier">title</span> <span class="ruby-identifier">attribute</span> <span class="ruby-keyword">and</span>
* <span class="ruby-identifier">a</span> <span class="ruby-identifier">titleized</span> <span class="ruby-identifier">version</span> <span class="ruby-identifier">of</span> <span class="ruby-identifier">the</span> <span class="ruby-identifier">last</span> <span class="ruby-identifier">key</span> <span class="ruby-identifier">segment</span> <span class="ruby-identifier">as</span> <span class="ruby-identifier">a</span> <span class="ruby-identifier">text</span>.
</pre>

<p>E.g. the value returned for a missing translation key :“blog.post.title”
will be &lt;span class=“translation_missing” title=“translation missing:
en.blog.post.title”&gt;Title&lt;/span&gt;. This way your views will display
rather reasonable strings but it will still be easy to spot missing
translations.</p>

<p>Second, it’ll scope the key by the current partial if the key starts with a
period. So if you call <code>translate(&quot;.foo&quot;)</code> from the
<code>people/index.html.erb</code> template, you’ll actually be calling
<code>I18n.translate(&quot;people.index.foo&quot;)</code>. This makes it
less repetitive to translate many keys within the same partials and gives
you a simple framework for scoping them consistently. If you don’t prepend
the key with a period, nothing is converted.</p>

<p>Third, it’ll mark the translation as safe <a
href="../../HTML.html">HTML</a> if the key has the suffix “_html” or the
last element of the key is the word “html”. For example, calling
translate(“footer_html”) or translate(“footer.html”) will return a safe <a
href="../../HTML.html">HTML</a> string that won’t be escaped by other <a
href="../../HTML.html">HTML</a> helper methods. This naming convention
helps to identify translations that include <a
href="../../HTML.html">HTML</a> tags so that you know what kind of output
to expect when you call translate in a template.</p>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="TranslationHelper.html#method-i-t">t</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-translate_source')" id="l_method-i-translate_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be4a4cd38ff2c2db0f6b69bb72fb3557bd5a6e21/actionpack/lib/action_view/helpers/translation_helper.rb#L46" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-translate_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/translation_helper.rb, line 46</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">translate</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-identifier">options</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-value">:rescue_format</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">:html</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:rescue_format</span>)
  <span class="ruby-identifier">options</span>[<span class="ruby-value">:default</span>] = <span class="ruby-identifier">wrap_translate_defaults</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:default</span>]) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:default</span>]
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">html_safe_translation_key?</span>(<span class="ruby-identifier">key</span>)
    <span class="ruby-identifier">html_safe_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">dup</span>
    <span class="ruby-identifier">options</span>.<span class="ruby-identifier">except</span>(*<span class="ruby-constant">I18n</span><span class="ruby-operator">::</span><span class="ruby-constant">RESERVED_KEYS</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">unless</span> <span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-value">:count</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Numeric</span>)
        <span class="ruby-identifier">html_safe_options</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-constant">ERB</span><span class="ruby-operator">::</span><span class="ruby-constant">Util</span>.<span class="ruby-identifier">html_escape</span>(<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>)
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">translation</span> = <span class="ruby-constant">I18n</span>.<span class="ruby-identifier">translate</span>(<span class="ruby-identifier">scope_key_by_partial</span>(<span class="ruby-identifier">key</span>), <span class="ruby-identifier">html_safe_options</span>)

    <span class="ruby-identifier">translation</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:html_safe</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">translation</span>.<span class="ruby-identifier">html_safe</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">translation</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-constant">I18n</span>.<span class="ruby-identifier">translate</span>(<span class="ruby-identifier">scope_key_by_partial</span>(<span class="ruby-identifier">key</span>), <span class="ruby-identifier">options</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    